

#ifndef XOTA_PB_PROTO_H__
#define XOTA_PB_PROTO_H__

#include <stdint.h>
#include <stdbool.h>

#define MAGIC_CODE							0xAB 
#define PB_PROTO_HEAD_SIZE					8 

// Flag offset 
#define PB_PROTO_HEAD_FLAG_VERSION			0 
#define PB_PROTO_HEAD_FLAG_ACK				4 		 
#define PB_PROTO_HEAD_FLAG_ERROR			5 
#define PB_PROTO_HEAD_FLAG_CRYPTO			6 

#define PB_PROTO_HEAD_FLAG_VERSION_MASK		0x0F
#define PB_PROTO_HEAD_FLAG_ACK_MASK			0x10 
#define PB_PROTO_HEAD_FLAG_ERROR_MASK		0x20 
#define PB_PROTO_HEAD_FLAG_CRYPTO_MASK		0xC0 

#define PB_PROTO_HEAD_FLAG_VERSION_0		0x00 
#define PB_PROTO_HEAD_FLAG_ACK_TRUE			0x10 
#define PB_PROTO_HEAD_FLAG_ACK_FALSE		0x00 
#define PB_PROTO_HEAD_FLAG_ERROR_TRUE		0x20 
#define PB_PROTO_HEAD_FLAG_ERROR_FALSE		0x00 
#define PB_PROTO_HEAD_FLAG_CRYPTO_NONE		0x00 
#define PB_PROTO_HEAD_FLAG_CRYPTO_AES128	0x40 

#define PB_PROTO_FLAG_DEFAULT				0x00
#define PB_PROTO_FLAG_RESP_ERROR			0x20 
#define PB_PROTO_FLAG_RESP_CRYPTO_AES		0x40 


#define PB_PROTO_COMMAND_OFFSET				0 
#define PB_PROTO_PAYLOAD_1_KEY_OFFSET		1 

#define FW_CONTENT_MAX_SIZE		(256 + 4 + 1) 
#define PACKETS_MAX_SIZE		FW_CONTENT_MAX_SIZE



typedef void (*pb_resp_handle_t)(const uint8_t* p_data, uint16_t size ); 

typedef struct{
	uint8_t 	magic; 
	uint8_t		flag; 
	uint16_t	length; 
	uint16_t 	crc; 
	uint16_t 	tid; 
	
	uint8_t* 	payload; 
}pb_proto_data_t; 


uint32_t xota_pb_proto_data_consume(  pb_proto_data_t * pb_data , pb_resp_handle_t pb_resp); 



#endif

